﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dimine.Core;
using Dimine.Entity;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            dmBlockDataCS block = new dmBlockDataCS();
            /*dmDbDatabaseCS db = dmDbDatabaseCS.FromDwg(@"D:\db\2012版示例数据\1 开始\1.1 文件\1.1.1 AOTOCAD数据\123.dwg");
            return;
            string filename = @"d:\db\test.dmb";
            dmBlockDataCS block = new dmBlockDataCS();
            double []ori=new double[3]{0,0,0};
            double []xyzlen=new double[3]{100,200,300};
            double []rot=new double[3]{24,45,65};
            double []used=new double[3]{12,34,65};
            dmBlockFieldTypeCollectionCS fields=new dmBlockFieldTypeCollectionCS();
            Console.WriteLine("添加字段:姓名\t字段类型:"+dmBlockFieldTypeCS.GetTypeName(3));
            fields.Add(new dmBlockFieldTypeCS("姓名", dmFieldTypeCS.eSTRING));
            Console.WriteLine("添加字段:性别\t字段类型:" + dmBlockFieldTypeCS.GetTypeName(4));
            fields.Add(new dmBlockFieldTypeCS("性别",dmFieldTypeCS.eBIT));
            Console.WriteLine("添加字段:年龄\t字段类型:" + dmBlockFieldTypeCS.GetTypeName(5));
            fields.Add(new dmBlockFieldTypeCS("年龄",dmFieldTypeCS.eUNSIGNEDCHAR));
            Console.WriteLine("****************************");
            Console.WriteLine("开始创建快段模型");
            if (block.Create(filename, ori, xyzlen, rot, used, fields))
            {
                Console.WriteLine("创建成功");
                Console.WriteLine("****************************");
                Console.WriteLine("开始关闭快段模型");
                if(block.Close())
                    Console.WriteLine("关闭快段模型成功!");
                else
                    Console.WriteLine("关闭快段模型失败!");
            }
            else
                Console.WriteLine("创建失败");
            Console.WriteLine("****************************");
            Console.WriteLine("开始读取快段模型");
            dmBlockDataCS newBlock = new dmBlockDataCS();
            int res=newBlock.Open(filename,20,false);
            if (res>0)
            {
                Console.WriteLine("快段模型以"+(res==1?"非":"")+"只读读取成功!");
                Console.WriteLine("****************************");
                Console.WriteLine("开始添加字段!");
                if (newBlock.AppendFields("uint16_t name; char sex; int16_t age;") > 0)
                    Console.WriteLine("字段添加成功!");
                else
                    Console.WriteLine("字段添加失败!");
                Console.WriteLine("****************************");
                Console.WriteLine("添加字段后快段模型的字段:");
                dmBlockFieldTypeCollectionCS flds = newBlock.FieldsType;
                int flen = flds.Count;
                for (int i = 0; i < flen; ++i)
                {
                    Console.WriteLine("字段名称:" + flds[i].Name + "\t字段类型:" + flds[i].Type);
                }
                Console.WriteLine("****************************");
                Console.WriteLine("开始移除字段!");
                if (newBlock.RemoveFields("name;sex;")>0)
                    Console.WriteLine("字段移除成功!");
                else
                    Console.WriteLine("字段移除失败!");
                Console.WriteLine("****************************");
                Console.WriteLine("移除字段后快段模型的字段:");
                flds = newBlock.FieldsType;
                flen = flds.Count;
                for (int i = 0; i < flen; ++i)
                {
                    Console.WriteLine("字段名称:" + flds[i].Name+"\t字段类型:"+flds[i].Type);
                }
            }
            else
            {
                Console.WriteLine("快段模型读取失败!");
            }
            Console.ReadLine();*/
        }
    }
}